<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.* , java.util.*" errorPage="" %>
<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", -1); //prevents caching at the proxy server
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Enganche Diferido</title>
<link rel="stylesheet" href="../css/arastyle.css" type="text/css">
<script>
function agregaEnganche(){
	document.forma.accion.value = "agrega";
	document.forma.submit();
}

function eliminar(cual){
	document.forma.accion.value = "elimina";
	document.forma.cual.value = cual;
	document.forma.submit();
}
</script>
</head>
<%
ArrayList enganches = (ArrayList)session.getAttribute("enganches");
String mes = (String)session.getAttribute("mes");
if(request.getParameter("accion")!=null){
	if(request.getParameter("accion").equals("agrega")){
		enganches.add(request.getParameter("montoEnganche"));
		session.setAttribute("enganches",enganches);
		session.setAttribute("mes",mes);
		%>
		<script>
			window.opener.document.forma.submit();
			window.close();
		</script>
	<%}else if(request.getParameter("accion").equals("elimina")){
			enganches.remove(Integer.parseInt(request.getParameter("cual")));
			session.setAttribute("enganches",enganches);
			%>
			<script>
				window.opener.document.forma.submit();
			</script>
	<%
		}
}

%>
<body>
<form name="forma" method="post" action="agregaEnganche.jsp">
<input name="accion" value="" type="hidden">
<input name="cual" value="" type="hidden">
<table border="0" cellpadding="1" cellspacing="1" width="80%" align="center">
	<th colspan="3" class="titulosPU">Enganches Diferidos</th>
<%
	for(int i=0; i<enganches.size();i++){
%>
	<tr>
		<td class="etiqueta" align="right"><%=i+1%></td>
		<td class="etiqueta" align="right"><%=enganches.get(i)%></td>
		<td class="etiqueta"><a href="javascript: eliminar(<%=i%>);"><img src="../images/icono_eliminar.gif" border="0"></a></td>
	</tr>
<%}%>
	<tr>
		<td width="40%" class="etiqueta" align="right"><%=enganches.size()+1%></td>
		<td width="50%" class="etiqueta" align="right"><input name="montoEnganche" size="10" class="textRigth"></td>
	</tr>
	<tr>
		<td class="etiqueta" colspan="2">Mes 1 pago:
			<select name="mes_pago">
				<option value="1">1</option>
				<%for(int j=0; j<enganches.size();j++){%>
					<option value="<%=j+2%>" <%=(mes.equals(""+j+2))?" selected":""%>><%=j+2%></option>
				<%}%>
			</select>&nbsp;<input class="boton" type="button" name="agrega" value="Agregar" onClick="javascript: agregaEnganche();"></td>
	</tr>
</table>
</form>
</body>
</html>
